﻿using AdverseEventReportSystem.BLL.EscortManageSys;
using AdverseEventReportSystem.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AdverseEventReportSystem.Web.Areas.Escort.Controllers
{
    public class EscortSummaryController : BaseController
    {
        // GET: Escort/EscortSummary
        public ActionResult Index()
        {
            ViewBag.CurrDepCode = loginUser.CurrDepCode;
            ViewBag.DepartCode = loginUser.DepartCode.Replace('&', ',');
            ViewBag.JobTitle = loginUser.JobTitle;
            return View();
        }

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Search()
        {
            string date = WebUtils.GetString("date");
            string departmentCode = WebUtils.GetString("departmentCode");
            if (departmentCode == "-1")
            {
                departmentCode = "'" + string.Join("','", loginUser.DepartCode.Split('&')) + "'";
            }
            else
            {
                departmentCode = "'" + departmentCode + "'";
            }
            EscortManageSysSoapClient service = new EscortManageSysSoapClient();
            ResultHelperOfString serviceResult = service.GetSummaryInfoByDate(date, departmentCode);
            if (serviceResult.S)
            {
                var jsonobj = JsonConvert.DeserializeObject<dynamic>(serviceResult.D);
                var result = new { Rows = jsonobj };
                return JsonDate(result);
            }

            return JsonDate(new { Total = 0, Rows = new DataTable() });
        }


        /// <summary>
        /// 获取陪护汇总导出数据
        /// </summary>
        /// <returns></returns>
        [LoginAttribute(IsNeed = false)]
        public ActionResult GetEscortSummaryPrint()
        {
            string date = WebUtils.GetString("date");
            string departmentCode = WebUtils.GetString("departmentCode");
            departmentCode = "'" + string.Join("','", departmentCode.Split(',')) + "'";
            EscortManageSysSoapClient service = new EscortManageSysSoapClient();
            ResultHelperOfString serviceResult = service.GetSummaryInfoByDate(date, departmentCode);
            if (serviceResult.S)
            {
                var jsonobj = JsonConvert.DeserializeObject<dynamic>(serviceResult.D);
                var result = new { Rows = jsonobj };
                return JsonDate(result);
            }
            else
            {
                return JsonDate(null);
            }
        }
    }
}